package Code.Day11_20241012.com.dx.day11;

import java.io.*;

public class SerializableObj {

	public static void main(String[] args) throws IOException, ClassNotFoundException {
//		ObjectOutputStream oos = null;
		ObjectInputStream ois=null;
		try {
//			// 创建ObjectOutputStream输出流
//			oos = new ObjectOutputStream(new FileOutputStream(
//					"D:\\AAA\\new_file.txt"));
//			Student stu = new Student("安娜", 30, "女");
//			System.out.println("姓名为："+stu.getName());
//			System.out.println("年龄为："+stu.getAge());
//			System.out.println("性别为："+stu.getGender());
//			// 对象序列化，写入输出流
//			oos.writeObject(stu);




			//创建ObjectInputStream输入流
			ois=new ObjectInputStream(
					new FileInputStream("D:\\AAA\\new_file.txt"));
			//反序列化，强转类型
			Student stu1=(Student)ois.readObject();
			//输出生成后对象信息
			System.out.println("姓名为："+stu1.getName());
			System.out.println("年龄为："+stu1.getAge());
			System.out.println("性别为："+stu1.getGender());
		} catch (IOException ex) {
			ex.printStackTrace();
		} finally {
			try {
//				if (oos != null) {
//					oos.close();
//				}
				if (ois != null) {
					ois.close();
				}
			}catch (IOException ex) {
				ex.printStackTrace();
			}         			
		}
	}
}
